package com.quasar.hpatient.dialog;

import android.app.Activity;
import android.widget.TextView;

import com.quasar.hpatient.R;

import java.util.Arrays;
import java.util.List;

import lib.quasar.base.dialog.BaseDialog;
import lib.quasar.util.CalendarUtil;
import lib.quasar.widget.wheel.WheelView;

/**
 * description: 选择日期, 小时, 分钟
 * created by kalu on 2018/3/29 9:03
 */
public class TimeDialog extends BaseDialog {

    private final List<String> hourList = Arrays.asList(
            "00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11",
            "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23");
    private final List<String> minuteList = Arrays.asList(
            "00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11",
            "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23",
            "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35",
            "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47",
            "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59");
    private String mMinute = CalendarUtil.getMinutes();
    private String mHour = CalendarUtil.getHours();
    private OnTimeChangeListener listener;

//    @Override
//    public void onBackPressed() {
//    }

    /************************************************/

    public TimeDialog(Activity activity) {
        super(activity);
    }

    @Override
    public void show() {
        super.show();
        //   setCanceledOnTouchOutside(false);
        // setCancelable(false);
    }

    @Override
    public void cancel() {

        if (null != listener) {
            listener.onTimeChange(mHour, mMinute);
        }

        super.cancel();
    }

    @Override
    protected int initView() {
        return R.layout.layout_dialog_time;
    }

    public void setTitles(String str) {
        TextView time = findViewById(R.id.layout_dialog_time_title);
        time.setText(str);
    }

    @Override
    protected void initData() {

        findViewById(R.id.layout_dialog_time_back).setOnClickListener(v -> dismiss());
        findViewById(R.id.layout_dialog_time_ok).setOnClickListener(v -> cancel());

        WheelView hour = findViewById(R.id.layout_dialog_time_hour);
        if (null != hour) {
            hour.setList(hourList);
            hour.setDefault(mHour);
            hour.setOnWheelChangeListener((index, str) -> mHour = str);
        }

        WheelView minute = findViewById(R.id.layout_dialog_time_minute);
        if (null != minute) {
            minute.setList(minuteList);
            minute.setDefault(mMinute);
            minute.setOnWheelChangeListener((index, str) -> mMinute = str);
        }
    }

    public void setOnTimeChangeListener(OnTimeChangeListener mListener) {
        this.listener = mListener;
    }

    public interface OnTimeChangeListener {
        void onTimeChange(String hour, String minute);
    }
}
